package com.keqing.tomato;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class LandscapeActivity extends AppCompatActivity {
    private TextView tvTime;
    private BroadcastReceiver broadcastReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landscape);
        Log.e("com/keqing/tomato", "LandscapeActivity - onCreate()");
        registerBroadcastReceivers();

        tvTime = findViewById(R.id.tv_time);
        Bundle bundle = getIntent().getExtras();
        String time = bundle.getString("time");
        if (time != null) {
            tvTime.setText(time);
        }
    }

    //广播接收倒计时
    private void registerBroadcastReceivers() {
        this.broadcastReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                Bundle bundle = intent.getExtras();
                String minSec = bundle.getString("minSec");
                tvTime.setText(minSec);
            }
        };
        registerReceiver(this.broadcastReceiver, new IntentFilter("timer"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("com/keqing/tomato", "LandscapeActivity - onDestroy()");
        unregisterReceiver(broadcastReceiver);
    }
}